let isUsernameExist;
let isSamePwd;
$(function () {
  $("#username").blur(function () {
    $.ajax({
      type: "get",
      url: "/users/checkUserName",
      data: { username: this.value },
      success: function (response) {
        if (response == 1) {
          isUsernameExist = 1;
          $("#usernameTip")
            .text("用户名已存在")
            .removeClass("text-muted")
            .addClass("text-danger");
        } else {
          isUsernameExist = 0;
          $("#usernameTip")
            .text("用户名可以使用")
            .removeClass("text-danger")
            .addClass("text-muted");
        }
      },
      error: function (e) {
        if (e.statusText == "timeout") {
          alert("请求超时");
        }
      },
    });
  });
  $("#emphasizepwd").blur(function () {
    if (this.value === $("#password").val()) {
      isSamePwd = 1;
    }
  });
});
function register() {
  //组织默认提交onsubmit
  if (isUsernameExist === 0 && isSamePwd === 1) {
    return true;
  } else {
    return false;
  }
}
function login() {
  $.ajax({
    type: "post",
    url: "/users/register",
    data: {},
  });
}
